package compro.admission.form.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import compro.admission.form.entity.User;
import compro.admission.form.service.UserService;

@Controller
public class RegisterController {
	private UserService userService;

	public UserService getUserService() {
		return userService;
	}

	@Resource
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	@RequestMapping(value="/registerInput")
	public String registerInput() {
		return "register";
	}
	
	@RequestMapping(value="/register", method=RequestMethod.POST)
	public String register(User user) {
		userService.saveUser(user);
		return "redirect:/";
	}
	
	@RequestMapping(value="register/validateEmail", method=RequestMethod.GET)
	public @ResponseBody String validateEmail(@RequestParam String email) {
		return userService.checkEmail(email);
	}
}
